class EventUtils {
    public static channel: Map<any,any> = new Map()
    func: Function
    lisent(func: Function){
        EventUtils.lisent(this, func);
        this.func = func;
    }

    close(){
        this.func = null
    }

    send_channel(data:any){
        this.func(data);
    }

    /** add lisent */
    public static lisent(item: any, func: Function){
        if(EventUtils.channel.get(item) != null){
            console.log("lisent:"+ item);
        }else{
            EventUtils.channel.set(item,func)
        }
    }

    /** send message by item */
    public static send_channel(item: any,data: any){
        let func = EventUtils.channel.get(item)
        if(func != null){
            func(data);
        }else{
            console.log("event is not found: " + item)
        }
    }

    /** close event by item */
    public static close(item: any){
        if(item != undefined){
            EventUtils.channel.delete(item)
        }
    }

}


export {EventUtils}